package com.hong.customization;

import com.hong.qrpc.TransportClient;
import com.hong.qrpc.selector.AbstractTransportSelector;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Random;

/**
 * 创建自定义的选择器，必须是一个bean对象才行，另外如果配置文件指定了选择器的话则会覆盖自定义选择器
 * 也可以通过spi去创建
 *
 * @Author HQT
 * @Date 2022/8/16 15:55
 */
//@Component
@Slf4j
public class CustomizationSelector extends AbstractTransportSelector {
    private Random random = new Random();

    {
        System.out.println("using CustomizationSelector");
    }

    @Override
    protected TransportClient select(ArrayList<TransportClient> clients) {
        return clients.get(random.nextInt(clients.size()));
    }
}
